//
//  LTLpictureView.m
//  WeiBo
//
//  Created by Apple_Lzzy46 on 16/11/1.
//  Copyright © 2016年 LTL. All rights reserved.
//

#import "LTLpictureView.h"
#import "LTLPhone.h"
#import "LTLPhotoView.h"
@implementation LTLpictureView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}
-(void)setPhone:(NSArray *)phone
{
    _phone = phone;
    //图片数
    NSInteger count = _phone.count;
    //清除self子控件
    [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    CGFloat w ;
    if (count == 1) {
        
        w = mainWidth-30;
        
    }
    else if ((count >=2 )&&(count <= 4))
    {
        w = (mainWidth-40)/2;
    }
    else
    {
        w = (mainWidth-50)/3;
    }
    CGRect Rect = CGRectMake(0, 0, w, w);
    
    [_phone enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        LTLPhone *model = obj;
        LTLPhotoView *image = [[LTLPhotoView alloc]init];
        
        if (count == 1){image.frame = Rect;}
        
        else if((count >=2 )&&(count <= 4)){image.frame = CGRectOffset(Rect, idx%2*(w+10), idx/2*(w+10));}
        
        else{image.frame = CGRectOffset(Rect, idx%3*(w+10), idx/3*(w+10));}
        
        image.backgroundColor = [UIColor blueColor];
        image.photo = model;
//        image.contentMode = UIViewContentModeScaleAspectFill;
        image.clipsToBounds = YES;
        [self addSubview:image];
        
    }];
    
}


@end
